{% extends "base.html" %}

{% block content %}
			<h4>单子名称：<span id="editWorkflowNname">{{workflowDetail.workflow_name}}</span></h4>
            <input type="hidden" id="workflowDetail_id" name="workflowid" value="{{workflowDetail.id}}">
            <input type="hidden" id="editSqlContent" value="{{workflowDetail.sql_content}}"/>
			<hr>	
			<table class="table table-striped table-hover">
				<thead>
					<tr>
						<th>
							上线发起人
						</th>
						<th>
							审核人
						</th>
						<th>
							上线集群
						</th>
						<th>
							发起时间
						</th>
						<th>
							结束时间
						</th>
						<th>
							是否备份
						</th>
						<th>
							当前状态
						</th>
					</tr>
				</thead>
				<tbody>
					<tr class="success">
						<td>
							{{workflowDetail.engineer}}
						</td>
						<td>
                            {{listAllReviewMen.0}} {{listAllReviewMen.1}}
						</td>
						<td>
							{{workflowDetail.cluster_name}}
						</td>
						<td>
							{{workflowDetail.create_time|date:"Y-m-d H:i:s"}}
						</td>
						<td>
							{{workflowDetail.finish_time|date:"Y-m-d H:i:s"}}
						</td>
						<td>
							{{workflowDetail.is_backup}}
						</td>
						<td>
							{% if workflowDetail.status == "已正常结束" %}
								<font color="green">
							{% else %}
								<font color="red">
							{% endif %}
								<B id="workflowDetail_status">{{workflowDetail.status}}</B></font>
						</td>
					</tr>
					
				</tbody>
			</table>

			<table class="table table-striped table-hover" width='100%' style='table-layout:fixed;'>
				<thead>
					<tr>
						<th width="40px">
							ID
						</th>
						<th>
							SQL内容
						</th>
						<th>
							自动审核结果
						</th>
						<th width="110px">
							扫描/影响行数
						</th>
						<th width="100px">
							执行耗时
						</th>
						<th width="100px">
							执行状态
						</th>
					</tr>
				</thead>
				<tbody>
					{% for row in listContent %}
					<tr>
						<td>
						{% if forloop.last %}
							<input type="hidden" id="sqlMaxRowNumber" value="{{row.0}}">
						{% endif %}
							{{forloop.counter}}
						</td>
					   <td style='word-wrap:break-word;'>
	 						{% for sql in row.5 %}
 								{{ sql }}{% if not forloop.last %}<br/>{% endif %}
							{% endfor %}
	 					</td>
 						<td style='word-wrap:break-word;'>
							{% for statement in row.4 %}
								{{ statement }}{% if not forloop.last %}<br/>{% endif %}
							{% endfor %}
						</td>
						<td>
							{{row.6}}
						</td>
						<td>
							{{row.9}}
						</td>
						<td id="td_{{forloop.counter}}">
                            {% if workflowDetail.status == "执行中" %}
							<div>
                                <div class="progress" style="width: 80%; height: 18px; float: left;">
                                    <div id="div_{{forloop.counter}}" class="progress-bar" role="progressbar" aria-valuenow="60"
                                        aria-valuemin="0" aria-valuemax="100" >
										<!--style="width: 100%;">-->
										<span id="span_{{forloop.counter}}"></span>
                                    </div>
                                </div>
								<div style="width: 10%; height: 18px; float: right;">
									<form  method="post" >
										{% csrf_token %}
										<input type="hidden" name="workflowid" value="{{workflowDetail.id}}">
										<!--<input type="hidden" id="sqlID_{{row.0}}" value="{{row.0}}">-->
										<button id="btnstop_{{row.0}}" value="{{row.0}}" type="button" class="close" style="display: none" title="停止pt-OSC进程">
										 <span aria-hidden="true">&times;</span>
										 <span class="sr-only"></span>
										</button>
									</form>
								</div>
							</div>
                            {% else %}
							    {{row.3}}
                            {% endif %}
						</td>
					</tr>
					{% endfor %}
					
				</tbody>
			</table>
			{% if workflowDetail.status == '等待审核人审核' %}
            {% if loginUser in listAllReviewMen %}
			<form action="/execute/" method="post" style="display:inline-block;">
				{% csrf_token %}
				<input type="hidden" name="workflowid" value="{{workflowDetail.id}}">
				<input type="submit" id="btnExecute" type="button" onclick="execute()" class="btn btn-primary btn-default" data-loading-text="Loading..." value="审核通过，执行" />
			</form>
			{% endif %}

			<form action="/cancel/" method="post" style="display:inline-block;">
				{% csrf_token %}
				<input type="hidden" name="workflowid" value="{{workflowDetail.id}}">
				<input type="submit" id="btnCancel" type="button" onclick="execute()" class="btn btn-default" data-loading-text="Loading..." value="终止流程" />
			</form>
			{% elif workflowDetail.status == '已正常结束' and workflowDetail.is_backup == '是' %}
			<form action="/rollback/" method="get" style="display:inline-block;">
                {% csrf_token %}
                <input type="hidden" name="workflowid" value="{{workflowDetail.id}}">
                <input type="submit" id="btnRollback" type="button" class="btn btn-default" data-loading-text="Loading..." value="查看回滚SQL" />
            </form>
			{% elif workflowDetail.status == '自动审核不通过' or workflowDetail.status == '人工终止流程' or workflowDetail.status == '执行有异常' %}
				{% if workflowDetail.engineer == loginUser %}
				<!--只允许发起人修改工单-->
					{% csrf_token %}
                	<a type='button' id="btnEditSql" class='btn btn-warning' href="/editsql/">重新修改</a>
				{% endif %}
			{% endif %}
{% endblock content%}
